const a = async function (
  _,
  { $grid, row },
  _2,
  { dayjs, dc: { open, http, store } }
) {
  const pageModel = "1778066883146883073";
  const formBase = "1778018090338689026";
  const formPlan = "1778361025647288321";
  const gridPlan = "1778371634002571266";
  const gridIncome = "1778585043470061569";
  const gridFile = "1778625325733449729";
  const year = dayjs(store.get("user", "date")).format("YYYY");
  const eFormZwxmBase = await http.form({
    url: "/zw/czItem/findItemByGuid",
    data: { GUID: row.GUID, YEAR: year },
  });
  const { list: eGridZwxmFile } = await http.form({
    url: "/zw/czItem/listFile",
    data: { ITEMGUID: row.GUID, YEAR: year },
  });
  const transfer = {
    GUID: row.GUID,
    [formPlan]: eFormZwxmBase,
    [formBase]: eFormZwxmBase,
    [gridFile]: eGridZwxmFile,
  };
  const layout = { id: pageModel };
  const modal = {
    title: "编辑项目",
    width: "75vw",
    height: document.body.clientHeight * 0.7,
    minHeight: document.body.clientHeight * 0.7,
    defaultFullscreen: false,
    centered: true,
    open: true,
    showOkBtn: true,
    showCancelBtn: true,
  };
  const inner = {
    onOk: async (_, { memory, origin }, { xe, dc: { close, http } }) => {
      const { get, isEmpty, isEqual, omit } = xe;
      const item = get(origin, formBase, {});
      Object.assign(item, get(origin, formPlan, {}));
      const subList = [];
      const subs = { [gridPlan]: 1, [gridIncome]: 2 };
      for (const key of Object.keys(subs)) {
        const list = get(origin, key, []);
        const bak = get(memory, key, []);
        const removed = bak
          .filter(({ GUID }) => list.findIndex((it) => it.GUID == GUID) < 0)
          .map((it) => ({ GUID: it.GUID, state: "removed" }));
        const changed = [];
        const added = [];
        for (const now of list) {
          const val = omit(now, ["id"]);
          if (isEmpty(val)) continue;
          const extra = { CTYPE: subs[key], ITEMGUID: item.GUID };
          if (!val.GUID) {
            const cid = (await http.get({ url: "/zw/czItem/getSubGuid" })).GUID;
            added.push({ ...val, ...extra, state: "added", GUID: cid });
            continue;
          }
          const old = bak.find(({ GUID }) => val.GUID == GUID);
          if (isEqual(val, old)) continue;
          changed.push({ ...val, ...extra, state: "modified", GUID: val.GUID });
        }
        subList.push(...removed, ...added, ...changed);
      }
      const fileList = [];
      const list = get(origin, gridFile, []);
      const bak = get(memory, gridFile, []);
      fileList.push(
        ...bak
          .filter(({ GUID }) => list.findIndex((it) => it.GUID == GUID) < 0)
          .map((it) => ({ GUID: it.GUID, state: "removed" }))
      );
      for (const now of list) {
        const val = omit(now, ["id"]);
        if (isEmpty(val)) continue;
        const extra = { ITEMGUID: item.GUID };
        if (!val.GUID) {
          const cid = (await http.get({ url: "/zw/czItem/getSubGuid" })).GUID;
          fileList.push({ ...val, ...extra, state: "added", GUID: cid });
          continue;
        }
        const old = bak.find(({ GUID }) => val.GUID == GUID);
        if (isEqual(val, old)) continue;
        fileList.push({ ...val, ...extra, state: "modified", GUID: val.GUID });
      }
      await http.post({
        url: "/zw/czItem/saveItem",
        data: { item, option: "modified", subList, fileList },
      });
      close(origin);
    },
  };
  console.log("inner click: ", $grid, row, { inner, layout, modal, transfer });
  open({ inner, layout, modal, transfer });
};